/*
   Copyright 2009 Abdulla Abdurakhmanov (abdulla@latestbit.com)
   Original sources are available at www.latestbit.com

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.

   IDataTypesCoder.hpp. Created on: 09.06.2009 13:51:30
*/


#ifndef IDATATYPESCODER_HPP_
#define IDATATYPESCODER_HPP_

#include "smartobjects/SmartObjectsDefs.hpp"

namespace smartobjects {

class IDataTypesCoder : public virtual RefObject {
public:
	SO_DLLPRFX virtual ~IDataTypesCoder();

	virtual const std::string& getAlgorithm() const = 0;

	virtual void encodeByte(const char value, ByteBuffer* buffer) = 0;
	virtual char decodeByte(ByteBuffer* buffer) = 0;
	virtual void encodeUByte(const unsigned char value, ByteBuffer* buffer) = 0;
	virtual unsigned char decodeUByte(ByteBuffer* buffer) = 0;

	virtual void encodeInt16(const short value, ByteBuffer* buffer) = 0;
	virtual short decodeInt16(ByteBuffer* buffer) = 0;
	virtual void encodeUInt16(const unsigned short value, ByteBuffer* buffer) = 0;
	virtual unsigned short decodeUInt16(ByteBuffer* buffer) = 0;

	virtual void encodeInt32(const int value, ByteBuffer* buffer) = 0;
	virtual int decodeInt32(ByteBuffer* buffer)= 0;
	virtual void encodeUInt32(const unsigned int value, ByteBuffer* buffer) = 0;
	virtual unsigned int decodeUInt32(ByteBuffer* buffer) = 0;

	virtual void encodeInt64(const boost::int64_t value, ByteBuffer* buffer) = 0;
	virtual boost::int64_t decodeInt64(ByteBuffer* buffer) = 0;
	virtual void encodeUInt64(const boost::uint64_t value, ByteBuffer* buffer) = 0;
	virtual boost::uint64_t decodeUInt64(ByteBuffer* buffer) = 0;

	virtual void encodeFloat(const float value, ByteBuffer* buffer) = 0;
	virtual float decodeFloat(ByteBuffer* buffer) = 0;
	virtual void encodeDouble(const double value, ByteBuffer* buffer) = 0;
	virtual double decodeDouble(ByteBuffer* buffer) = 0;

	virtual void encodeBigInteger(const BigInteger& value, ByteBuffer* buffer) = 0;
	virtual void decodeBigInteger(BigInteger& toValue, ByteBuffer* buffer) = 0;
	virtual void encodeBigDecimal(const BigDecimal& value, ByteBuffer* buffer) = 0;
	virtual void decodeBigDecimal(BigDecimal& toValue, ByteBuffer* buffer) = 0;

	virtual void encodeString(const std::string& value, ByteBuffer* buffer, bool bEmptyAsNull=false) = 0;
	virtual void decodeString(std::string& toString, ByteBuffer* buffer) = 0;
	virtual void encodeWString(const std::wstring& value, ByteBuffer* buffer, bool bEmptyAsNull=false) = 0;
	virtual void decodeWString(std::wstring& toString, ByteBuffer* buffer) = 0;

	virtual void encodeChar(const char value, ByteBuffer* buffer) = 0;
	virtual char decodeChar(ByteBuffer* buffer) = 0;
	virtual void encodeWChar(const wchar_t value, ByteBuffer* buffer) = 0;
	virtual wchar_t decodeWChar(ByteBuffer* buffer) = 0;

	virtual void encodeBoolean(const bool value, ByteBuffer* buffer) = 0;
	virtual bool decodeBoolean(ByteBuffer* buffer) = 0;

	virtual void encodeDateTime(const time_t value, ByteBuffer* buffer) = 0;
	virtual time_t decodeDateTime(ByteBuffer* buffer) = 0;

	virtual void encodeByteArray(const std::vector<char>& value, ByteBuffer* buffer) = 0;
	virtual void decodeByteArray(std::vector<char>& toValue, ByteBuffer* buffer) = 0;
	virtual void encodeUByteArray(const std::vector<unsigned char>& value, ByteBuffer* buffer) =0;
	virtual void decodeUByteArray(std::vector<unsigned char>& toValue, ByteBuffer* buffer) =0;

	virtual void encodeInt16Array(const std::vector<short>& value, ByteBuffer* buffer) =0;
	virtual void decodeInt16Array(std::vector<short>& toValue, ByteBuffer* buffer) =0;
	virtual void encodeUInt16Array(const std::vector<unsigned short>& value, ByteBuffer* buffer) =0;
	virtual void decodeUInt16Array(std::vector<unsigned short>& toValue, ByteBuffer* buffer) =0;

	virtual void encodeInt32Array(const std::vector<int>& value, ByteBuffer* buffer) =0;
	virtual void decodeInt32Array(std::vector<int>& toValue, ByteBuffer* buffer) =0;
	virtual void encodeUInt32Array(const std::vector<unsigned int>& value, ByteBuffer* buffer) =0;
	virtual void decodeUInt32Array(std::vector<unsigned int>& toValue, ByteBuffer* buffer) =0;

	virtual void encodeInt64Array(const std::vector<boost::int64_t>& value, ByteBuffer* buffer) =0;
	virtual void decodeInt64Array(std::vector<boost::int64_t>& toValue, ByteBuffer* buffer) =0;
	virtual void encodeUInt64Array(const std::vector<boost::uint64_t>& value, ByteBuffer* buffer) =0;
	virtual void decodeUInt64Array(std::vector<boost::uint64_t>& toValue, ByteBuffer* buffer) =0;

	virtual void encodeFloatArray(const std::vector<float>& value, ByteBuffer* buffer) =0;
	virtual void decodeFloatArray(std::vector<float>& toValue, ByteBuffer* buffer) =0;
	virtual void encodeDoubleArray(const std::vector<double>& value, ByteBuffer* buffer) =0;
	virtual void decodeDoubleArray(std::vector<double>& toValue, ByteBuffer* buffer) =0;

	virtual void encodeBigIntegerArray(const std::vector<BigInteger>& fromArray, ByteBuffer* buffer) = 0;
	virtual void decodeBigIntegerArray(std::vector<BigInteger>& toArray, ByteBuffer* buffer ) = 0;
	virtual void encodeBigDecimalArray(const std::vector<BigDecimal>& fromArray, ByteBuffer* buffer) = 0;
	virtual void decodeBigDecimalArray(std::vector<BigDecimal>& toArray, ByteBuffer* buffer ) = 0;

	virtual void encodeStringArray(const std::vector<std::string>& fromArray, ByteBuffer* buffer) = 0;
	virtual void decodeStringArray(std::vector<std::string>& toArray, ByteBuffer* buffer ) = 0;
	virtual void encodeWStringArray(const std::vector<std::wstring>& fromArray, ByteBuffer* buffer) = 0;
	virtual void decodeWStringArray(std::vector<std::wstring>& toArray, ByteBuffer* buffer) = 0;

	virtual void encodeCharArray(const std::vector<char>& value, ByteBuffer* buffer) = 0;
	virtual void decodeCharArray(std::vector<char>& value, ByteBuffer* buffer) = 0;

	virtual void encodeWCharArray(const std::vector<wchar_t>& value, ByteBuffer* buffer) = 0;
	virtual void decodeWCharArray(std::vector<wchar_t>& value, ByteBuffer* buffer) = 0;

	virtual void encodeBooleanArray(const std::vector<bool>& value, ByteBuffer* buffer) = 0;
	virtual void decodeBooleanArray(std::vector<bool>& value, ByteBuffer* buffer) = 0;

	virtual void encodeDateTimeArray(const std::vector<time_t>& value, ByteBuffer* buffer) = 0;
	virtual void decodeDateTimeArray(std::vector<time_t>& value, ByteBuffer* buffer) = 0;

	virtual void encodeObjectArray(const unsigned int arraySize, ByteBuffer* buffer) = 0;
	virtual unsigned int decodeObjectArray( ByteBuffer* buffer ) = 0;

	virtual unsigned int encodeObjectListBegin( ByteBuffer* buffer ) = 0;
	virtual unsigned int decodeObjectListBegin(ByteBuffer* buffer) = 0;

	virtual void encodeObjectListEnd(unsigned int nBeginPos, unsigned int nCount, ByteBuffer* buffer ) = 0;
	virtual void decodeObjectListEnd(ByteBuffer* buffer) = 0;

	virtual void encodeObjectMap(const unsigned int mapSize, ByteBuffer* buffer) = 0;
	virtual unsigned int decodeObjectMap(ByteBuffer* buffer) = 0;

	virtual void encodeNull(ByteBuffer* buffer) = 0;
	virtual bool decodeNull(ByteBuffer* buffer) = 0;

	virtual void encodeStructureDataTypeBegin(ByteBuffer* buffer) = 0;
	virtual bool decodeStructureDataTypeBegin(ByteBuffer* buffer) = 0;

	virtual void encodeStructureDataTypeEnd(ByteBuffer* buffer) = 0;
	virtual void decodeStructureDataTypeEnd(ByteBuffer* buffer) = 0;

	virtual unsigned int encodeNamedDataPartBegin ( const std::string& structurePartName, ByteBuffer* buffer ) = 0;
	virtual unsigned int decodeNamedDataPartBegin ( const std::string& structurePartName, ByteBuffer* buffer) = 0;

	virtual void encodeNamedDataPartEnd ( const unsigned int beginPos, ByteBuffer* buffer ) = 0;
	virtual void decodeNamedDataPartEnd ( const unsigned int beginPos, ByteBuffer* buffer ) = 0;

	virtual void encodeEnumDataType(const int selectedIndex, ByteBuffer* buffer) = 0;
	virtual int decodeEnumDataType(ByteBuffer* buffer) = 0;

	virtual void encodeExceptionDataTypeBegin(ByteBuffer* buffer) = 0;
	virtual bool decodeExceptionDataTypeBegin(ByteBuffer* buffer) = 0;
	virtual void encodeExceptionDataTypeEnd(ByteBuffer* buffer) = 0;
	virtual void decodeExceptionDataTypeEnd(ByteBuffer* buffer) = 0;

	virtual unsigned int encodeEncryptedDataTypeBegin( ByteBuffer* buffer ) = 0;
	virtual unsigned int decodeEncryptedDataTypeBegin( ByteBuffer* buffer ) = 0;
	virtual void encodeEncryptedDataTypeEnd( const unsigned int beginPos, ByteBuffer* buffer ) = 0;
	virtual void decodeEncryptedDataTypeEnd( ByteBuffer* buffer ) = 0;

	virtual void encodeObjectType ( const std::string& className, ByteBuffer* buffer ) = 0;
	virtual void decodeObjectType(std::string& className, ByteBuffer* buffer ) = 0;

	virtual unsigned int encodeChoiceDataTypeBegin(ByteBuffer* buffer) = 0;
	virtual unsigned int decodeChoiceDataTypeBegin(ByteBuffer* buffer) = 0;
	virtual void encodeChoiceSelectedField(const std::string& selectedField, ByteBuffer* buffer) = 0;
	virtual void decodeChoiceSelectedField(std::string& selectedField, ByteBuffer* buffer) = 0;
	virtual void encodeChoiceDataTypeEnd(const unsigned int beginPos, ByteBuffer* buffer) = 0;
	virtual void decodeChoiceDataTypeEnd(const unsigned int beginPos, ByteBuffer* buffer) = 0;

	virtual void encodeGrammar(ByteBuffer* buffer) = 0;
	virtual void decodeGrammar(ByteBuffer* buffer) = 0;

	virtual void reset() = 0;

};

}

#endif /* IDATATYPESCODER_HPP_ */
